import {defineStore} from "pinia";
import {getDiseaseList,getTop5Disease,plussSearchCount} from "@/api/pet/disease.js";
import {plussXinWenPower} from "@/api/web/news.js";



const useDiseaseStore = defineStore(
    'disease',
    {
        state: () => ({
                //全部疾病信息
        diseaseList:[] as API.Disease[],
        diseaseListGEN:[] as API.Disease[],
        top5Disease:[] as API.Disease[],
        disease:{} as API.Disease

        }),
        getters: {

        },
        actions: {

                // 查询全部
                getDiseaseList(){
                        return new Promise((resolve, reject) => {
                                console.log("=============getDiseaseList()")
                                getDiseaseList().then((res: any) => {
                                        // console.log(res)
                                        this.diseaseList = res.rows
                                        this.diseaseListGEN = res.rows
                                        resolve()
                                }).catch((error: any) => {
                                        reject(error)
                                        console.log(error)
                                })
                        })
                },
                //获取5条
                getTop5Disease(){
                        return new Promise((resolve, reject) => {
                                console.log("=============getTop5Disease()")
                                getTop5Disease().then((res: any) => {
                                        // console.log(res)
                                        this.top5Disease = res.rows
                                        resolve()
                                }).catch((error: any) => {
                                        reject(error)
                                        console.log(error)
                                })
                        })
                },
                //获取疾病详细信息
               getInfo(disease:API.Disease){
                         this.disease = disease
                         return new Promise( (resolve, reject) => {
                                 console.log("=============增加疾病信息power")
                                plussSearchCount(disease).then((res: any) => {
                                         resolve()
                                 }).catch((error: any) => {
                                         reject(error)
                                         console.log(error)
                                 })
                         })
                },
                //更新搜索查询到的结果
                updateDiseaseList(list:[]){
                        console.log(list)
                        this.diseaseList=list
                        console.log(this.diseaseList)
                }
        }

    })



export default useDiseaseStore
